<template>
  <div class="download_box">
    <oldDownload
      v-if="isOldVersion"
      :id="id"
      :patientName="patientName"
      :createDate="createDate"
      :dataObj="dataObj"
      :imgUrl="imgUrl"
      :mouthImgs="mouthImgs"
    ></oldDownload>
    <newDownload
      v-else
      :id="id"
      :patientName="patientName"
      :createDate="createDate"
      :dataObj="dataObj"
      :imgUrl="imgUrl"
      :mouthImgs="mouthImgs"
    ></newDownload>
  </div>
</template>

<script>
import { isOldVersionBool } from '@/utils/index';
import oldDownload from './common/oldDownload.vue';
import newDownload from './common/newDownload.vue';
export default {
  // 下载
  name: 'BLZMasterDownload',
  components: {
    oldDownload,
    newDownload,
  },
  data() {
    return {
      // 区分是老版本还是新版本
      isOldVersion: false,
    };
  },

  props: {
    id: Number,
    patientName: String,
    createDate: String,
    dataObj: Object,
    imgUrl: String,
    mouthImgs: Array,
  },

  created() {
    this.getOrderDownload();
  },
  mounted() {},

  methods: {
    getOrderDownload() {
     

      this.$http
        .post(`/orderDownload/list?orderId=${this.$route.query.id}&fileType=1`)
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          } else {
            if (res.data[0].clientVersion) {
              let currentVersion = res.data[0].clientVersion;
              // 比较大小
              if (isOldVersionBool(currentVersion, this.$config.versionBoundary)) {
                this.isOldVersion = true;
              } else {
                this.isOldVersion = false;
              }
            } else {
              // 为空的话就是老版本
              this.isOldVersion = true;
            }
          }
        })
        .catch((err) => {
          console.log('err', err);
        });
    },
  },
};
</script>

<style lang="scss" scoped>
</style>
